﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PathUtility.cs" company="">
//   
// </copyright>
// <summary>
//   The path utility.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Libium.Core
{
    using System.IO;
    using System.Reflection;

    /// <summary>
    ///   The path utility.
    /// </summary>
    public static class PathUtility
    {
        #region Public Methods and Operators

        /// <summary>
        /// The get extension without dot.
        /// </summary>
        /// <param name="path">
        /// The path. 
        /// </param>
        /// <returns>
        /// The <see cref="string"/> . 
        /// </returns>
        public static string GetExtensionWithoutDot(string path)
        {
            var extension = Path.GetExtension(path);
            return extension != null ? extension.TrimStart('.') : null;
        }

        /// <summary>
        ///   The get temporary directory path.
        /// </summary>
        /// <returns> The <see cref="string" /> . </returns>
        public static string GetTemporaryDirectoryPath()
        {
            var directoryPath = Path.Combine(Path.GetTempPath(), Assembly.GetEntryAssembly().GetName().Name);
            Directory.CreateDirectory(directoryPath);
            return directoryPath;
        }

        /// <summary>
        /// The get temporary file path.
        /// </summary>
        /// <param name="fileName">
        /// The file name. 
        /// </param>
        /// <returns>
        /// The <see cref="string"/> . 
        /// </returns>
        public static string GetTemporaryFilePath(string fileName)
        {
            var directoryPath = GetTemporaryDirectoryPath();
            return Path.Combine(directoryPath, fileName);
        }

        /// <summary>
        ///   The get temporary file path without extension.
        /// </summary>
        /// <returns> The <see cref="string" /> . </returns>
        public static string GetTemporaryFilePathWithoutExtension()
        {
            var directoryPath = GetTemporaryDirectoryPath();
            return Path.Combine(directoryPath, Path.GetRandomFileName());
        }

        #endregion
    }
}